package com.tqjc.execute.utils;

import com.alibaba.fastjson2.JSONObject;

/**
 * @Description: 公共返回结果类
 * @author: pzy
 * @date: 2023年05月18日 16:05
 */

public class PublicResult<T> {
    public T getData() {
        return data;
    }

    private boolean success;
    private String msg;
    private T data;


    /**
     * create by: pzy
     * description: 正确方法
     * create time: 2022/2/21 10:15
     *
     * @return com.tqjc.c19032.semiautomatic.SemiworkResult<T>
     * @param: [data]
     */
    public static PublicResult ok() {
        PublicResult res = new PublicResult();
        res.setSuccess(true);
        res.setMsg("操作成功");
        return res;
    }

    public static <T> PublicResult<T> ok(T data) {
        PublicResult res = new PublicResult();
        res.setData(data);
        res.setSuccess(true);
        res.setMsg("操作成功");
        return res;
    }


    /**
     * create by: pzy
     * description: 错误结果
     * create time: 2022/2/21 10:15
     *
     * @return com.tqjc.c19032.semiautomatic.SemiworkResult<T>
     * @param: String
     */
    public static PublicResult fail(String msg) {
        PublicResult res = new PublicResult();
        res.setSuccess(false);
        res.setMsg(msg);
        return res;
    }

//    public SemiworkResult fail(T data) {
//        SemiworkResult res = new SemiworkResult();
//        res.setSuccess(false);
//        res.setData(data);
//        return res;
//    }


    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }


}